/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       ipconnection.h
 * Author:     karooolek
 * Created on: 2009-03-14
 *
 **********************************************************************************************************************/

#ifndef IPCONNECTION_H_
#define IPCONNECTION_H_

#include "connection.h"
#include "ipaddress.h"
#ifdef WIN32
#include <winsock.h>
typedef int socklen_t;
#else
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
typedef int SOCKET;
#define SOCKET_ERROR -1
#define INVALID_SOCKET -1
#endif

namespace mGameEngine
{
namespace Network
{

/**
 * Connection over IP network.
 */
class IPConnection: public Connection
{
protected:
    /**
     * IP address.
     */
    IPAddress _ipaddr;

    /**
     * Socket descriptor.
     */
    SOCKET _socket;

public:
    /**
     * Create new IP connection.
     */
    IPConnection();

    /**
     * Create new IP connection with specified address.
     * @param ipaddr IP address.
     */
    IPConnection(const IPAddress &ipaddr);

    /**
     * Destroy IP connection
     * @return
     */
    virtual ~IPConnection();

    /**
     * Get connection IP address.
     * @return connection IP address.
     */
    const IPAddress &getIPAddress() const
    {
        return _ipaddr;
    }

    /**
     * Set connection IP address.
     * @param ipaddr IP address.
     */
    void setIPAddress(const IPAddress &ipaddr)
    {
        _ipaddr = ipaddr;
    }
};

}
}

#endif // IPCONNECTION_H_
